package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fulbitofacil.exception.DAOExcepcion;
import fulbitofacil.modelo.CanchaFul;
import fulbitofacil.negocio.ServiciosAdNegocio;

/**
 * Servlet implementation class DetalleServAdServlet
 */
@WebServlet("/DetalleServAdServlet")
public class DetalleServAdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DetalleServAdServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("DetalleServAdServlet");
		// TODO Auto-generated method stub
		int idCancha = Integer.parseInt(request.getParameter("txtidCancha"));
		String servicio = request.getParameter("txtTipoServicio");
		String descrip = request.getParameter("txtDescripcion");
		double tarifa = Double.parseDouble(request.getParameter("txtTarifa"));
		
		ServiciosAdNegocio negocio = new ServiciosAdNegocio();
		CanchaFul canchita = new CanchaFul();
		canchita.setIdCanchaFul(idCancha);
		String ruta = "mensajeConfirmacion.jsp";
		try {
			
			negocio.InsertarServiciosAd(servicio, descrip, tarifa, canchita);
			
			ruta = ruta + "?mensaje=Se registro exitosamente el servicio";
			RequestDispatcher rd2 = request.getRequestDispatcher(ruta);
			rd2.forward(request, response);
		} catch (DAOExcepcion e) {
			ruta = ruta + "?mensaje=No se pudo registrar el servicio. Error en la BD";
			RequestDispatcher rd3 = request.getRequestDispatcher(ruta);
			rd3.forward(request, response);
			e.printStackTrace();
		}
	}

}
